<template>
  <div v-show="showMark" :style="{ width: dialogWidth, height: dialogHeight }" class="video-map-popup">
    <div class="popup-title">
      <slot name="title"></slot>
      <span class="close" @click="close">x</span>
    </div>
    <div class="title-background"></div>
    <slot name="main"></slot>
  </div>
</template>

<script>
/**
 * 地图弹出框
 *
 * @author 阳坤
 * @since  2022/11/15
 * */

export default {
  name: 'VideoMapPopup',

  data() {
    return {
      dialogHeight: '2.25rem',
      dialogWidth: '4rem',
      theme: 'dialog-blue', // 主题
      showMark: false // 显示标签
    }
  },

  methods: {
    /**
     * 显示地图弹出框
     * */
    showPopup(width, height, theme, lngLat, offsetLngLat = null) {
      try {
        this.dialogWidth = width / 100 + 'rem' || '4rem'
        this.dialogHeight = height / 100 + 'rem' || '2.5rem'
        this.theme = theme
        const infoWindow = new AMap.InfoWindow({
          isCustom: true, // 使用自定义窗体
          content: this.$el,
          offset: new AMap.Pixel(0, -30)
        })
        this.showMark = true
        infoWindow.open(this.$mapSdk().map, lngLat)

        this.$mapSdk().setMvMapCenterAndZoom(offsetLngLat || lngLat, 13)
      } catch (e) {
        console.log(e)
      }
    },

    close() {
      this.$mapSdk().setMvMapClickMarker()
      this.hidePopup()
    },
    hidePopup() {
      this.showMark = false
      this.$mapSdk().map.clearInfoWindow()
    },
    mounted() {
      this.$nextTick(() => {
        // 禁用右键
        document.oncontextmenu = new Function('event.returnValue=false')
        // 禁用选择
        document.onselectstart = new Function('event.returnValue=false')
      })
    }
  }
}
</script>

<style scoped lang="less">
/deep/.mz-panel-content {
  .title {
    font-size: 20px !important;
    font-family: 'pangmenzhengdaoregular';
    font-weight: 400 !important;
    color: #266bf4 !important;
    line-height: 30px !important;
  }
}

.video-map-popup {
  .popup-title {
    position: absolute;
    left: 0;
    color: #fff;
    width: 100%;
    height: 31px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9;
  }

  .title-background {
    width: 100%;
    height: 31px;
    position: absolute;
    left: 0;
    opacity: 0.2;
    background: #000000;
  }
  /deep/ .bounced-content {
    padding-bottom: 0;
    // background: #fff;
  }
  /deep/ .title-name {
    width: 85%;
    text-align: center;
    text-overflow: ellipsis;
    white-space: nowrap;
    overflow: hidden;
  }

  .close {
    position: absolute;
    right: 14px;
    top: 6px;
    cursor: pointer;
    font-size: 20px;
    color: #fff;
    line-height: 1;
  }
}
</style>
